package com.fm.app03.Activity;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.KeyEvent;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.fm.app03.R;

public class webActivity extends AppCompatActivity {


    /*界面视图*/
    WebView myWebview;

    @SuppressLint("SetJavaScriptEnabled")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        /*显示视图*/
        setContentView(R.layout.activity_web);
        /*获取加载的界面视图*/
        myWebview = (WebView) findViewById(R.id.web_content);
        /************************** web设置 ******************************/
        /*允许JavaScript*/
        myWebview.getSettings().setJavaScriptEnabled(true);
        /*webView访问文件*/
        myWebview.getSettings().setAllowFileAccess(true);
        myWebview.getSettings().setAllowContentAccess(true);
        /*允许缩放*/
        myWebview.getSettings().setBuiltInZoomControls(true);

        /************************** 加载路由 *************************************/
        /*加载界面*/
        myWebview.loadUrl("https://www.heikedreamer.top");
        /*加载html*/
        //myWebview.loadUrl("file:///android_asset/xiaomi/index.html");
        /*内嵌显示*/
        myWebview.setWebViewClient(new WebViewClient());

    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        /*返回键返回上一页*/
        if(keyCode == KeyEvent.KEYCODE_BACK){
            if(myWebview.canGoBack()){
                myWebview.goBack();
                return true;
            }
        }

        /*清除缓存*/
        myWebview.clearCache(true);
        return super.onKeyDown(keyCode, event);

    }






}